<template>
	<view class='content'>
		<view class="message-box">
			<view class="message-item" v-for="(item,index) in list" :key='index'>
				<view class="flex">
					<view class="money">
						<view class="">
							摄像头名称：{{ item.cameraName}}
						</view>
						<view class="">
							摄像头编码：{{ item.serialNumber}}
						</view>
						<view class="money">
							创建时间：{{ changeTime(item.create_time)}}
						</view>
					</view>
					<view class="">
						<u-button class="" size="mini" text="查看" type="primary" @click='gotoVideoDetail(item)'></u-button>
					</view>
				</view>
				<view class="flex">
					
				</view>
			</view>
			<view class="nodata" v-if="list.length == 0">
				暂无数据
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				device_id: '',
				list: []
			}
		},
		onLoad(option){
			console.log(option)
			this.device_id = option.device_id
			this.getvideoList()
		},
		methods: {
			gotoVideoDetail(item){
				uni.navigateTo({
					url:'/pages/admin/videoDetail?id='+item.id
				})
			},
			changeTime(time){
				const dateObj = new Date(time * 1000);
				 
				// 获取年月日时分秒
				let year = dateObj.getFullYear();
				let month = (dateObj.getMonth() + 1).toString().padStart(2, '0');
				let day = dateObj.getDate().toString().padStart(2, '0');
				let hours = dateObj.getHours().toString().padStart(2, '0');
				let minutes = dateObj.getMinutes().toString().padStart(2, '0');
				let seconds = dateObj.getSeconds().toString().padStart(2, '0');
				
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
			},
			getvideoList(){
				var _this = this
				uni.request({
					url: 'http://www.yndzfl.cn/wxsite/User/getdevcameralist',
					method: 'POST',
					header:{
						"Content-Type" : "application/x-www-form-urlencoded"
					},
					data: {
						openid: uni.getStorageSync('OPENID'),
						device_id: _this.device_id
					},
					success(res) {
						console.log(res)
						if(res.data.code == 1){
							_this.list = res.data.data
						}else if(res.data.code == -1){
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}else if(res.data.code == 408){
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
							uni.reLaunch({
								url: '/pages/admin/login'
							})
						}	
						
					}
				})
			}
		}
	}
</script>

<style scoped>
.message-box{
	/* width: 100%; */
	min-height: 100%;
	padding: 28rpx;
}
.message-item{
	background-color: #fff;
	border-radius: 1rpx;
	padding: 20rpx 24rpx;
	margin-bottom: 27rpx;
}
.flex{
	display: flex;
	justify-content: space-between;
	align-items: center;
	line-height: 30px;
}
.msgtitle{
	font-weight: 600;
	font-size: 15px;
}
.money{
	color: #999;
}
.status{
	font-size: 25px;
}
.nodata{
	text-align: center;
}
</style>
